%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% PRESENT MAIN LAND-USE REGRESSION TABLES

% "DEFORESTATION IN THE AMAZON:
% A UNIFIED FRAMEWORK FOR ESTIMATION AND POLICY ANALYSIS"

% by Eduardo Souza-Rodrigues

% This version: November 2018

% OBSERVATIONS: 
% Run this program after running "dem_def_reg.m"

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% (A) LOAD DATA

% Load Estimated Coefficients and Standard Errors (calculated in "dem_def_reg.m")
load beta_ols_farm_1;
load beta_iv_farm_1;
load beta_qr_farm_1;
load beta_ivqr_farm_1;
load pvalue_overid_farm_1;

load beta_ols_farm_2;
load beta_iv_farm_2;
load beta_qr_farm_2;
load beta_ivqr_farm_2;
load pvalue_overid_farm_2;

load beta_ols_farm_3;
load beta_iv_farm_3;
load beta_qr_farm_3;
load beta_ivqr_farm_3;
load pvalue_overid_farm_3;

load beta_ols_farm_4;
load beta_iv_farm_4;
load beta_qr_farm_4;
load beta_ivqr_farm_4;
load pvalue_overid_farm_4;

% Load Marginal Effects
load margeff_farm_1;
load margeff_farm_2;
load margeff_farm_3;
load margeff_farm_4;


%% (B) SHOW ESTIMATED RESULTS

disp('----------------------------------------------------------------------------')
disp('----------------------------------------------------------------------------')
disp('LAND-USE REGRESSIONS, LOGIT MODEL - COEFFICIENTS ON TC')       
table(round([beta_ols_farm_1(1,1);beta_ols_farm_1(1,2);nan;nan;beta_ols_farm_2(1,1);beta_ols_farm_2(1,2);nan;nan;...
    beta_ols_farm_3(1,1);beta_ols_farm_3(1,2),;nan;nan;beta_ols_farm_4(1,1);beta_ols_farm_4(1,2);nan;nan],4),...
    round([nan;nan;beta_iv_farm_1(1,1);beta_iv_farm_1(1,2);nan;nan;beta_iv_farm_2(1,1);beta_iv_farm_2(1,2);...
    nan;nan;beta_iv_farm_3(1,1);beta_iv_farm_3(1,2);nan;nan;beta_iv_farm_4(1,1);beta_iv_farm_4(1,2)],4),...
    round([beta_qr_farm_1(1,1);beta_qr_farm_1(1,6);beta_ivqr_farm_1(1,1);beta_ivqr_farm_1(1,6);...
    beta_qr_farm_2(1,1);beta_qr_farm_2(1,6);beta_ivqr_farm_2(1,1);beta_ivqr_farm_2(1,6);...
    beta_qr_farm_3(1,1);beta_qr_farm_3(1,6);beta_ivqr_farm_3(1,1);beta_ivqr_farm_3(1,6);...
    beta_qr_farm_4(1,1);beta_qr_farm_4(1,6);beta_ivqr_farm_4(1,1);beta_ivqr_farm_4(1,6)],4),...
    round([beta_qr_farm_1(1,2);beta_qr_farm_1(1,7);beta_ivqr_farm_1(1,2);beta_ivqr_farm_1(1,7);...
    beta_qr_farm_2(1,2);beta_qr_farm_2(1,7);beta_ivqr_farm_2(1,2);beta_ivqr_farm_2(1,7);...
    beta_qr_farm_3(1,2);beta_qr_farm_3(1,7);beta_ivqr_farm_3(1,2);beta_ivqr_farm_3(1,7);...
    beta_qr_farm_4(1,2);beta_qr_farm_4(1,7);beta_ivqr_farm_4(1,2);beta_ivqr_farm_4(1,7)],4),...
    round([beta_qr_farm_1(1,3);beta_qr_farm_1(1,8);beta_ivqr_farm_1(1,3);beta_ivqr_farm_1(1,8);...
    beta_qr_farm_2(1,3);beta_qr_farm_2(1,8);beta_ivqr_farm_2(1,3);beta_ivqr_farm_2(1,8);...
    beta_qr_farm_3(1,3);beta_qr_farm_3(1,8);beta_ivqr_farm_3(1,3);beta_ivqr_farm_3(1,8);...
    beta_qr_farm_4(1,3);beta_qr_farm_4(1,8);beta_ivqr_farm_4(1,3);beta_ivqr_farm_4(1,8)],4),...
    round([beta_qr_farm_1(1,4);beta_qr_farm_1(1,9);beta_ivqr_farm_1(1,4);beta_ivqr_farm_1(1,9);...
    beta_qr_farm_2(1,4);beta_qr_farm_2(1,9);beta_ivqr_farm_2(1,4);beta_ivqr_farm_2(1,9);...
    beta_qr_farm_3(1,4);beta_qr_farm_3(1,9);beta_ivqr_farm_3(1,4);beta_ivqr_farm_3(1,9);...
    beta_qr_farm_4(1,4);beta_qr_farm_4(1,9);beta_ivqr_farm_4(1,4);beta_ivqr_farm_4(1,9)],4),...
    round([beta_qr_farm_1(1,5);beta_qr_farm_1(1,10);beta_ivqr_farm_1(1,5);beta_ivqr_farm_1(1,10);...
    beta_qr_farm_2(1,5);beta_qr_farm_2(1,10);beta_ivqr_farm_2(1,5);beta_ivqr_farm_2(1,10);...
    beta_qr_farm_3(1,5);beta_qr_farm_3(1,10);beta_ivqr_farm_3(1,5);beta_ivqr_farm_3(1,10);...
    beta_qr_farm_4(1,5);beta_qr_farm_4(1,10);beta_ivqr_farm_4(1,5);beta_ivqr_farm_4(1,10)],4),...
    'VariableNames',{'OLS','TwoSLS','Q10','Q25','Q50','Q75','Q90'},...
    'RowNames',{'SMALL         NO IV - Coeff','SMALL         NO IV - se','SMALL         IV    - Coeff','SMALL         IV    - se',...
    'SMALL-MEDIUM  NO IV - Coeff','SMALL-MEDIUM  NO IV - se','SMALL-MEDIUM  IV    - Coeff','SMALL-MEDIUM  IV    - se',...
    'MEDIUM-LARGE  NO IV - Coeff','MEDIUM-LARGE  NO IV - se','MEDIUM-LARGE  IV    - Coeff','MEDIUM-LARGE  IV    - se',...
    'LARGE         NO IV - Coeff','LARGE         NO IV - se','LARGE         IV    - Coeff','LARGE         IV    - se'})

if d_iv == 0        % use both dist_port and dist_cap as IV -- Main Specification
    
    table([obs_farm_1;pvalue_overid_farm_1],[obs_farm_2;pvalue_overid_farm_2],...
        [obs_farm_3;pvalue_overid_farm_3],[obs_farm_4;pvalue_overid_farm_4],...
        'VariableNames',{'SMALL','SMALL_MEDIUM','MEDIUM_LARGE','LARGE'},...
        'RowNames',{'Number of Obs','OverIdentification Test, p-values'})

elseif d_iv == 1    % use only dist_port as IV -- Appendix (just identified model)
    
    table(obs_farm_1,obs_farm_2,obs_farm_3,obs_farm_4,...
        'VariableNames',{'SMALL','SMALL_MEDIUM','MEDIUM_LARGE','LARGE'},...
        'RowNames',{'Number of Obs'})
    
end
       
pause

disp('----------------------------------------------------------------------------')
disp('MARGINAL EFFECTS OF TRANSPORTATION COSTS ON SHARE OF DEFORESTATION (Covariates at Sample Mean)')       
table(round([margeff_farm_1(:,1);margeff_farm_2(:,1);margeff_farm_3(:,1);margeff_farm_4(:,1)],3),...
    round([margeff_farm_1(:,2);margeff_farm_2(:,2);margeff_farm_3(:,2);margeff_farm_4(:,2)],3),...
    round([margeff_farm_1(:,3);margeff_farm_2(:,3);margeff_farm_3(:,3);margeff_farm_4(:,3)],3),...
    round([margeff_farm_1(:,4);margeff_farm_2(:,4);margeff_farm_3(:,4);margeff_farm_4(:,4)],3),...
    round([margeff_farm_1(:,5);margeff_farm_2(:,5);margeff_farm_3(:,5);margeff_farm_4(:,5)],3),...
    round([margeff_farm_1(:,6);margeff_farm_2(:,6);margeff_farm_3(:,6);margeff_farm_4(:,6)],3),...
    'VariableNames',{'TwoSLS','Q10','Q25','Q50','Q75','Q90'},'RowNames',...
    {'SMALL        - Prop of Deforestation','SMALL        - Marginal Effect',...
     'SMALL-MEDIUM - Prop of Deforestation','SMALL-MEDIUM - Marginal Effect',...
     'MEDIUM-LARGE - Prop of Deforestation','MEDIUM-LARGE - Marginal Effect',...
     'LARGE        - Prop of Deforestation','LARGE        - Marginal Effect'})
 disp('----------------------------------------------------------------------------')
pause
